package logic

import (
	"context"
	"gorm.io/gorm"
	"house_srv/house"
	"house_srv/internal/svc"
	"house_srv/models"

	"github.com/zeromicro/go-zero/core/logx"
)

type HouseUpdateLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewHouseUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *HouseUpdateLogic {
	return &HouseUpdateLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 房源修改
func (l *HouseUpdateLogic) HouseUpdate(in *house.HouseUpdateRequest) (*house.HouseUpdateResponse, error) {
	// todo: add your logic here and delete this line
	houses := models.House{
		Model: gorm.Model{
			ID: uint(in.Id),
		},
		UserId:   in.UserId,
		Title:    in.Title,
		MinPrice: float64(in.MinPrice),
		MaxPrice: float64(in.MaxPrice),
		Price:    float64(in.Price),
		Address:  in.Address,
		Image:    in.Image,
		Size:     in.Size,
		Staus:    in.Status,
	}
	models.DB.Debug().Updates(&houses)

	return &house.HouseUpdateResponse{
		Id:       int64(houses.ID),
		Title:    houses.Title,
		Image:    houses.Image,
		Address:  houses.Address,
		UserId:   houses.UserId,
		MinPrice: float32(houses.MinPrice),
		MaxPrice: float32(houses.MaxPrice),
		Price:    float32(houses.Price),
		Size:     houses.Size,
		Status:   houses.Staus,
	}, nil
}
